//
//  GSCommonLoginPointAlertLabelView.m
//  GSLoginDemo
//
//  Created by guoshikeji_a on 2018/7/30.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "GSCommonLoginPointAlertLabelView.h"

@interface GSCommonLoginPointAlertLabelView ()

@property (nonatomic, strong) UILabel *label;

@end

@implementation GSCommonLoginPointAlertLabelView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.clipsToBounds = true;
        [self setupSubviews];
    }
    return self;
}
- (void)setupSubviews {
    self.label = [UILabel new];
    self.label.numberOfLines = 0;
//    self.label.lineBreakMode = NSLineBreakByWordWrapping;
    self.label.textColor = GSLOGINRGBRGBHEX(0x666666);
    self.label.lineBreakMode = NSLineBreakByCharWrapping;
    self.label.font = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
    [self addSubview:self.label];
    //
    CGFloat leftPadding = 15.0/2+4.0;
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(leftPadding);
        make.top.mas_equalTo(self);
        make.width.mas_equalTo(self).offset(-leftPadding);
        make.bottom.mas_equalTo(self);
    }];
    //
    CGFloat pointWidth = 15.0/2;
    UIView *pointView = [UIView new];
    pointView.layer.cornerRadius = pointWidth/2;
    pointView.layer.masksToBounds = true;
    pointView.backgroundColor = GSLOGIN_THEME_COLOR;
    [self addSubview:pointView];
    [pointView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self);
        make.width.height.mas_equalTo(pointWidth);
        make.top.mas_equalTo(self.label.font.lineHeight/2-pointWidth/2);
    }];
}

- (void)setAlertString:(NSString *)alertString {
    _alertString = alertString;
    self.label.text = alertString;
    CGSize size = [self systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(size.height);
    }];
}

@end
